package com.cx.file.model;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 * @author cx
 * @description: 接口返回结果
 * @date 2022/3/1 9:09
 */
@Data
@ApiModel("接口返回结果")
public class Result<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private static final int SUCCESS_CODE = 0;
    private static final int KNOW_ERROR_CODE = -1;

    @ApiModelProperty(value = "状态码", example = "0")
    private Integer code;

    @ApiModelProperty(value = "提示信息", example = "success")
    private String msg;

    @ApiModelProperty(value = "数据", example = "xxx")
    private T data;

    private Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static Result<Object> success() {
        return new Result<>(SUCCESS_CODE, "success", null);
    }

    public static <T> Result<T> success(T t) {
        return new Result<>(SUCCESS_CODE, "success", t);
    }

    public static Result<Object> error(String msg) {
        return new Result<>(KNOW_ERROR_CODE, msg, null);
    }


}
